package com.vlong.town.service.insurance;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.vlong.town.entity.insurance.InsuranceInfo;
import com.vlong.town.mapper.insurance.InsuranceInfoMapper;

/**
 * 保险信息业务实现类
 * @author Assassin
 */
@Service
public class InsuranceInfoService {

    // Fields

    @Autowired
    private InsuranceInfoMapper insuranceInfoMapper;// 保险信息Mapper接口

    // Methods

    /**
     * 添加保险信息
     * @param townId 村镇Id
     * @param title 保险标题
     * @param content 保险内容
     * @param desc 保险简介
     * @param thumbnail 缩略图
     */
    @Transactional
    public void add(Long townId, String insuranceType,String title, String content, String desc, String thumbnail) {
        InsuranceInfo insuranceInfo = new InsuranceInfo();
        insuranceInfo.setTownId(townId);
        insuranceInfo.setState(1);
        insuranceInfo.setStatus(1);
        insuranceInfo.setInsuranceType(insuranceType);
        insuranceInfo.setTitle(title);
        insuranceInfo.setContent(content);
        insuranceInfo.setDesc(desc);
        insuranceInfo.setThumbnail(thumbnail);
        Long cuTime = System.currentTimeMillis();
        insuranceInfo.setCreateTime(cuTime);
        insuranceInfo.setUpdateTime(cuTime);
        this.insuranceInfoMapper.insert(insuranceInfo);
    }

    /**
     * 逻辑删除保险信息
     * @param insuranceId 主键值
     */
    @Transactional
    public void delete(Long insuranceId) {
        this.insuranceInfoMapper.delete(insuranceId);
    }

    /**
     * 修改保险信息
     * @param insuranceId 保险Id
     * @param title 保险标题
     * @param content 保险内容
     * @param desc 保险简介
     * @param thumbnail 缩略图
     */
    @Transactional
    public void update(Long insuranceId, String insuranceType,String title, String content, String desc, String thumbnail) {
        InsuranceInfo insuranceInfo = new InsuranceInfo();
        insuranceInfo.setInsuranceId(insuranceId);
        insuranceInfo.setInsuranceType(insuranceType);
        insuranceInfo.setTitle(title);
        insuranceInfo.setContent(content);
        insuranceInfo.setDesc(desc);
        insuranceInfo.setThumbnail(thumbnail);
        insuranceInfo.setUpdateTime(System.currentTimeMillis());
        this.insuranceInfoMapper.update(insuranceInfo);
    }

    /**
     * 主键查询保险信息
     * @param insuranceId 保险Id
     * @return
     */
    @Transactional(readOnly = true)
    public InsuranceInfo queryById(Long insuranceId) {
        return this.insuranceInfoMapper.selectById(insuranceId);
    }

    /**
     * 查询保险信息
     * @param title 保险标题
     * @param content 保险内容
     * @param desc 保险简介
     * @return List<InsuranceInfo>
     */
    @Transactional(readOnly = true)
    public List<InsuranceInfo> queryList(String insuranceType,String title, String content, String desc) {
        InsuranceInfo insuranceInfo = new InsuranceInfo();
        insuranceInfo.setInsuranceType(insuranceType);
        insuranceInfo.setTitle(title);
        insuranceInfo.setContent(content);
        insuranceInfo.setDesc(desc);
        return this.insuranceInfoMapper.selectList(insuranceInfo);
    }

}
